﻿using System;
using System.Windows.Forms;
using AutoIt_IDE;

namespace AutoIt_Elements.GUI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
			using(About tmpAboutFrm = new About())
				tmpAboutFrm.ShowDialog();
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (BaseSettings bs = new BaseSettings())
                bs.ShowDialog();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.ExitApplication();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            // Check for corrupted Language
            if (Program.langManager.CurrentLanguage.IsCorrupted)
            {
                MessageBox.Show("Warning! The current language file seems to be corrupted. Please contact the author!", "Corrupted language file detected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
			else
			{
				// Load Language
				foreach(ToolStripMenuItem m in menuStrip1.Items)
				{
					this.ParseMenuItem(m);
			    }
			}
        }

		private void ParseMenuItem(ToolStripMenuItem item)
		{
            String itemTokenValue = Program.langManager.getTokenValue(item.Name);

            if (itemTokenValue != String.Empty)
                item.Text = itemTokenValue;

			if(item.HasDropDownItems)
			{
				// Parse subitems
				foreach(ToolStripItem subItem in item.DropDownItems)
				{
					if(typeof(ToolStripMenuItem).IsAssignableFrom(subItem.GetType()))
					{
						this.ParseMenuItem(subItem as ToolStripMenuItem);
					}
				}
			}
		}
    }
}
